import { ActionTree, ActionContext } from "vuex"
import { RootState } from "@/store";
import { Mutations } from "./mutations";
import { UserConstant } from "./constant"
import type { UserState } from "./state"

type AugmentedActionContext = {
  commit<K extends keyof Mutations>(
    key: K,
    payload: Parameters<Mutations[K]>[1]
  ): ReturnType<Mutations[K]>
} & Omit<ActionContext<UserState, RootState>, 'commit'>

/**
 * 定义 Actions
 */
export interface Actions {
  [UserConstant.ACTION_LOGIN_OUT]({ commit }: AugmentedActionContext, user: any): void
}

export const actions:Actions & ActionTree<UserState, RootState> = {
  [UserConstant.ACTION_LOGIN_OUT](
    { commit }: AugmentedActionContext,
    user: any
  ) {
    
    commit(UserConstant.MUTATION_LOGIN_OUT, "")
  }
}